package jgl.vajra.operator.part.mine.activity;

import android.text.TextUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

import jgl.vajra.operator.R;
import jgl.vajra.operator.databinding.ActivityBankCarEditBinding;
import jgl.vajra.operator.event.BankCardEditEvent;
import jgl.vajra.operator.part.mine.contract.BankCardEditContract;
import jgl.vajra.operator.part.mine.viewModel.BankCardEditViewModel;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.retrofithelper.utils.AEACCoder;
import jgl.vajra.operator.widget.utils.ToastUtils;

@CreateViewModel(BankCardEditViewModel.class)
public class BankCardEditActivity extends BaseMVVMActivity<BankCardEditViewModel, ActivityBankCarEditBinding> implements BankCardEditContract.View {
    @Override
    public int getLayoutId() {
        return R.layout.activity_bank_car_edit;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);
    }

    @Override
    public void onDetermine() {
        String name = mBinding.etName.getText().toString().trim();
        String accountNumber = mBinding.etAccountNumber.getText().toString().trim();
        String openBank = mBinding.etOpenBank.getText().toString().trim();
        String openArea = mBinding.etOpenArea.getText().toString().trim();
        String openBranch = mBinding.etOpenBranch.getText().toString().trim();

        if (TextUtils.isEmpty(name)) {
            ToastUtils.showShort("请输入账户号");
            return;
        }

        if (TextUtils.isEmpty(openBank)) {
            ToastUtils.showShort("请输入开户银行");
            return;
        }

        if (TextUtils.isEmpty(accountNumber)) {
            ToastUtils.showShort("请输入银行卡号");
            return;
        }


        if (TextUtils.isEmpty(openArea)) {
            ToastUtils.showShort("请输入开户地区");
            return;
        }

        if (TextUtils.isEmpty(openBranch)) {
            ToastUtils.showShort("请输入开户支行");
            return;
        }

        Map<String, Object> map = new HashMap<>();

        map.put("type", 1);//1-银行，2-微信，3-支付宝
        map.put("name", name);
        map.put("accountNumber", AEACCoder.encrypt(accountNumber));
        map.put("openBank", openBank);
        map.put("openArea", openArea);
        map.put("openBranch", openBranch);

        mViewModel.bindBankCardData(map);

    }

    @Override
    public void returnBindBankCardData() {
        EventBus.getDefault().post(new BankCardEditEvent());
        finish();
    }
}
